#include "optimum.h"
#include "ui_optimum.h"
#include <iostream>
using namespace std;

Optimum::Optimum(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Optimum)
{
	ui->setupUi(this);
//	void signalGetFunc(CFuncX *&f, Piped &p); /*QFuncX*/
//	void signalGo(CFuncX *f, const Piped &p, vector<double> &min, list<vector<double> > &experiments); /*QMethodX*/
//	void signalPlot(CFuncX *f, const Piped &p, const vector<double> &min, const list<vector<double> > &listOfExperiments); /*QPlotX*/

	QObject::connect(this,SIGNAL(signalGetFunc(CFuncX *&, Piped &)),
					 ui->qFuncX, SLOT(getFunc(CFuncX *&, Piped &))
					 );
	QObject::connect(this,SIGNAL(signalGo(CFuncX *, const Piped &, vector<double> &, list<vector<double> > &)),
					 ui->qMethodX, SLOT(go(CFuncX *, const Piped &, vector<double> &, list<vector<double> > &))
					 );
	QObject::connect(this,SIGNAL(signalPlot(CFuncX *, const Piped &, const vector<double> &, const list<vector<double> > &)),
					 ui->qPlotX, SLOT(plot(CFuncX *, const Piped &, const vector<double> &, const list<vector<double> > &))
					 );
}

Optimum::~Optimum()
{
    delete ui;
}

void Optimum::on_pushButton_released()
{
	CFuncX *f = NULL;
	Piped p;
	vector<double> min(2);
	list<vector<double> > experiments;


	emit signalGetFunc(f, p); /*QFuncX*/
	emit signalGo(f, p, min, experiments); /*QMethodX*/
	emit signalPlot(f, p, min, experiments); /*QPlotX*/

	QString sMin;
	
	for (int i = 1; i < min.size(); ++i)
	{
		sMin += " " + QString::number(min[i]);
	}

	QMessageBox::information( 0, "Result", "X_min = (" + sMin + ")" + "\nf(X_min) = " + QString::number(min[0]) );
}
